package com.vf.admin.miaodong.controller.agent;

import com.vf.admin.client.service.AgentUserCollectionService;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.entity.Result;
import com.vf.admin.miaodong.entity.AgentUserCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/agent/collection")
public class AgentCollectionController extends BaseController {

    @Autowired
    AppUserService appUserService;
    @Autowired
    AgentUserCollectionService agentUserCollectionService;

    @RequestMapping("/get")
    public Result index(Integer userId) {
        Map<String, Object> data = new HashMap<>();
        AgentUserCollection collection = agentUserCollectionService.findByUserId(userId);
        data.put("data", collection);
        return sucessJSON(data);
    }

    @RequestMapping("/saveOrUpdate")
    public Result saveOrUpdate(AgentUserCollection params) {
        AgentUserCollection collection = agentUserCollectionService.findByUserId(params.getAgentUserId());
        agentUserCollectionService.saveOrUpdate(params);
        return sucessJSON(collection);
    }
}
